<?php


/**
 * Radcodes - SocialEngine Module
 *
 * @category   Application_Extensions
 * @package    Game
 * @copyright  Copyright (c) 2009-2010 Radcodes LLC (http://www.radcodes.com)
 * @license    http://www.radcodes.com/license/
 * @version    $Id$
 * @author     Vincent Van <vincent@radcodes.com>
 */
 
 
?>

<div class="games_browse">
<?php if ($this->paginator->getTotalItemCount()): ?> 

  <h3 class="sep">
    <span>
      <?php if ($this->categoryObject): ?>
        <?php echo $this->translate('%s Games', $this->translate($this->categoryObject->getTitle())); ?>
      <?php else: ?>  
        <?php echo $this->translate('All Games'); ?>
      <?php endif; ?>
    </span>
  </h3>

  <?php if( $this->tag || $this->keyword):?>
    <div class="games_result_filter_details">
      <?php echo $this->translate('Showing games'); ?>    
      <?php if ($this->tag): ?>
        <?php echo $this->translate('tagging #%s', $this->htmlLink(
          $this->url(array('action'=>'manage', 'tag'=>$this->tag), 'game_general', true),
          $this->tagObject ? $this->tagObject->text : $this->tag
        ));?>
      <?php endif; ?>
      <?php if ($this->keyword): ?>
        <?php echo $this->translate('with %s keyword', $this->htmlLink(
          $this->url(array('action'=>'manage', 'keyword'=>$this->keyword), 'game_general', true),
          $this->keyword
        ));?>
      <?php endif; ?>         
      <?php echo $this->htmlLink(array('action'=>'manage', 'route'=>'game_general'), $this->translate('(x)'))?>
    </div>
  <?php endif; ?>
  
    <ul class="games_rows">
      <?php foreach( $this->paginator as $game ): ?>
        <li class="games_rows_featured_<?php echo $game->featured ? 'yes' : 'no'; ?> games_rows_sponsored_<?php echo $game->sponsored ? 'yes' : 'no'; ?>">
          <div class="game_photo">
            <?php echo $this->htmlLink($game->getHref(), $this->itemPhoto($game, 'thumb.normal'));?>
          </div>
          <div class="game_content">
            <div class="game_title">
              <?php echo $this->partial('index/_title.tpl', 'game', array('game' => $game, 'max_title_length' => 24))?>
            </div>
            <?php if ($game->getDescription()): ?>
              <div class="game_description">
                <?php echo $this->radcodes()->text()->truncate($game->getDescription(), 64); ?>
              </div>
            <?php endif; ?>           
            <div class="game_details">
              <?php 
                $meta_options = array(
                  'game' => $game,
                  'show_category' => true,
                  'show_created' => true,
                );
              ?>
              <?php echo $this->partial('index/_meta.tpl', 'game', $meta_options)?>
            </div>
            <div class="game_meta">
              <?php 
                $meta_options = array(
                  'game' => $game,
                  'show_favorites' => true, 
                  'show_views' => true,
                  'show_comments' => true,
                  //'show_likes' => true,
                );
              ?>
              <?php echo $this->partial('index/_meta.tpl', 'game', $meta_options)?>
            </div>
          </div>
          <?php if ($game->leaderboard_enabled): ?>
            <div class="game_icons">
              <span class="game_icon_leaderboard<?php if (!$game->leaderboard_enabled) echo "_off"?>"></span>
            </div>
          <?php endif;?>
          
          <div class="game_options" style="display: none">
            <?php if ($game->authorization()->isAllowed($this->viewer(), 'edit')): ?>
              <?php echo $this->htmlLink($game->getHref(array('action'=>'edit')), $this->translate('Edit Game'), array('class'=>'buttonlink icon_game_edit'))?>
            <?php endif; ?>
            <?php if ($game->authorization()->isAllowed($this->viewer(), 'delete')): ?>
              <?php echo $this->htmlLink($game->getHref(array('action'=>'delete')), $this->translate('Delete Game'), array('class'=>'buttonlink icon_game_delete'))?>
            <?php endif; ?>
          </div>
          
        </li>
      <?php endforeach; ?>
    </ul>
    
    <?php echo $this->paginationControl($this->paginator, null, null, array(
      'query' => $this->formValues
    )); ?>  
       
<script type="text/javascript">
en4.core.runonce.add(function(){       

  $$('ul.games_rows > li').addEvents({
	    mouseover: function(){
	    	this.getChildren('.game_options').show();
	    },
	    mouseout: function(){
	    	this.getChildren('.game_options').hide();
	    }
  });
  
});
</script>
        
<?php elseif ( $this->tag || $this->keyword || $this->category): ?>       
  <div class="tip">
    <span>
      <?php echo $this->translate('You do not have any games with that criteria.');?>
    </span>
  </div>
<?php else: ?>    
  <div class="tip">
    <span>
      <?php echo $this->translate('You do not have any games.');?>
    </span>
  </div>
<?php endif; ?>
</div>